package com.qingcheng.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.qingcheng.pojo.seckill.SeckillGoods;
import com.qingcheng.service.seckill.SeckillGoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;

import java.util.List;

@Service
public class SeckillGoodsServiceImpl implements SeckillGoodsService {

    @Autowired
    private RedisTemplate redisTemplate;


    /**
     * 根据时间区间查询秒杀商品列表
     *
     * @param time
     * @return
     */
    @Override
    public List<SeckillGoods> findAllGoods(String time) {
        //SeckillGoods_2021020316 这种形式的key
        String key = "SeckillGoods_"+time;
        return redisTemplate.boundHashOps(key).values();
    }


    /**
     * 根据时间段和商品id查询商品
     * @param time 时间段的开始时间
     * @param id 商品id
     * @return
     */
    public SeckillGoods one(String time,Long id){
        String key = "SeckillGoods_"+time;
        return (SeckillGoods) redisTemplate.boundHashOps(key).get(id);
    }
}
